package com.secondmybatis.mapper;


import com.secondmybatis.entity.Emp;
import com.secondmybatis.entity.EmpQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmpMapper {
    /**
     * 统计员工总数量
     * */
//    @Select("select count(*) from emp")
//    Long count();
//
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id limit #{start},#{pageSize}")
//    List<Emp> page(Integer start, Integer pageSize);

    /**
     * 采用插件PageHelper实现分页查询
     * */
//    @Select("select t1.*,t2.name deptName from emp t1 left join dept t2 on t1.dept_id = t2.id")
//    List<Emp> list(String name,Integer gender);

    /**
     * 采用插件PageHelper实现条件分页查询
     */
//    @Select("select t1.*,t2.name deptName from emp t1 left join dept t2 on t1.dept_id = t2.id")
    List<Emp> list(EmpQueryParam param);

    /**
     * 新增员工信息
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")   // 获取主键的值并赋给id属性
    @Insert("insert into emp(null,#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId}," +
            "#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /**
     * 批量删除员工信息
     * 基于XML动态SQL删除
     *
     * @param ids
     */
    void deleteBatch(List<Integer> ids);

    /**
     * 根据id查询员工基本信息及员工经历->返回多条数据，非一条数据
     *
     * @param id
     * @return
     */
//    @Select("select * from emp e left join emp_expr ee on e.id =ee.emp_id where e.id=#{id}")
    Emp getById(Integer id);

    @Select("select * from emp where id = #{id}")
    Emp getById2(Integer id);

    /**
     * 更新员工->动态SQL
     *
     * @param emp
     */

    void update(Emp emp);

    /**
     * 根据用户名和密码查询--登录操作
     * @param emp
     * @return
     */
    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp selectUsernameAndPassword(Emp emp);
}
